<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>菜单列表</title>
  <link rel="stylesheet" href="./css/style.css" />
</head>

<body>
  <h3 class="big-tit">菜谱列表</h3>
  <ul class="list-box">
    <!-- <li>
      <a href="info.html">
        <img src="http://yun.itheima.com/Upload/Images/20220627/62b924298e658.jpg" alt="" />
        <h3>菜单名称</h3>
      </a>
    </li> -->
  </ul>
  <p class="more">数据正在加载中...</p>
  <p class="noinfo">没有数据了...</p>
  <script src="/jquery.js"></script>
  <script src="/axios.js"></script>
  <script>
    // const q ={
    //   pageNum :1,
    //   pageSize:35,
    //   name:''
    // }
    // $.ajax({
    //   method:'get',
    //   url:'http://124.223.14.236:3001/api/recipe',
    //   data:q,
    //   success:function(res){
    //     console.log(res);
    //     const htmlGet = res.data.list.map(function(item,i){
    //       return `
    //       <li id="${item.id}">
    //   <a href="info.html">
    //     <img src="http://124.223.14.236:3001/public/${item.img}" alt="" />
    //     <h3>${item.name}</h3>
    //      </a>
    //    </li>
    //       `
    //     }).join('')
    //     $('.list-box').html(htmlGet)  
    //   }
    // })
    //   $('.list-box').on('click','li',function(e){
    //      let id = $(this).attr('id')
    //      localStorage.setItem('key',id)
    //    })


   
    // 根路径
  axios.defaults.baseURL = 'http://124.223.14.236:3001/api'

getlist()
async function getlist() {

  const { data: { data: res } } = await axios.get('/recipe')

  console.log(res);
  const str = res.list.map(item => {
    const { img, name, description, id } = item
    return `
        <li>
          <a href="/06-recipeBaseCode/info.html?id=${id}">
            <img src='http://124.223.14.236:3001/public/${img}' title="${description}" />
            <h3>${name}</h3>
          </a>
        </li>
        `
  }).join('')
  $('.list-box').html(str)
}
  </script>
</body>

</html>